(function($,owner){
	/*
	 * dateType
	 * YYYY-MM-DD-W hh:ss:mm
	 */
	
	owner.getCurrentDate = function(dateType,successBlock){
		var ymdwArr = dateType.split(' ');
		var today = new Date();
		var destStr = '';
		if (ymdwArr.length == 1) {
			var ymdwStr = ymdwArr[0];
			if (ymdwStr.indexOf(':') == -1) {//年月日周几
				destStr = dealYmdw(ymdwStr,today);
			}else{//时分秒
				destStr = dealHsm(ymdwStr,today)
			}
		}else{
			destStr = dealYmdw(ymdwArr[0],today) + ' ';
			destStr += dealHsm(ymdwArr[1],today)
		}
		owner.today = destStr;
		return destStr;
	};
	/*
	 * 截取天
	 */
	owner.getDateDay = function(dateStr){
		var dayStr = dateStr.substring(dateStr.length -2);
		return dayStr;
	}
	/*
	 * 获取后一天
	 */
	owner.getNextDate = function(dayStr){
		var sdate = changeStrToDate(dayStr);
		var daytime = sdate.getTime() + 1000 * 60 * 60 * 24;
		var newDate = new Date(daytime);
		var thisDay = changeDateToStr(newDate);
		return thisDay;
	}
	/*
	 * 获取前一天
	 */
	owner.getPreviousDate = function(dayStr){
		var sdate = changeStrToDate(dayStr);
		var daytime = sdate.getTime() - 1000 * 60 * 60 * 12;
		var newDate = new Date(daytime);
		var thisDay = changeDateToStr(newDate);
		return thisDay;
	}
	/*
	 * 获取一个月的周末数组
	 */
	owner.getMonthWeekend = function(dateStr){
		var dayArr = getYearMonthDay(dateStr);
		var month = dayArr[1];
		if (month < 10) {
			month = '0' + month;
		}
		var dateArr = [];
		var yearMonth = dayArr[0] + '-' + month;
		var dayStr = dayArr[0] + '-' + month + '-01';
		for (var i = 0; i < 6;i++) {
			var oneArr = owner.getWholeWeek(dayStr);
			var sat = oneArr[5].substring(0,7);//周六
			if (sat == yearMonth) {
				dateArr.push(oneArr[5]);
			}
			var sun = oneArr[6].substring(0,7);//周日
			if (sun == yearMonth) {
				dateArr.push(oneArr[6]);
			}else{
				break;
			}
			dayStr = addSomeDayToDate(dayStr,7);
		}
		return dateArr;
	}
	/*
	 * 获取完整周数组
	 */
	owner.getWholeWeek = function(dateStr){
		var weekInt = owner.getNumberWeekday(dateStr);
		var weekArr = [];
		var dayStr = dateStr;
		for (var i = weekInt; i < 8;i++) {
			if (i == weekInt) {
				weekArr[i - 1] = dayStr;
			}else{
				dayStr = owner.getNextDate(dayStr);
				weekArr[i - 1] = dayStr;
			}
		}
		var dayStr = dateStr;
		for (var i = weekInt -1; i > 0;i--) {
			dayStr = owner.getPreviousDate(dayStr);
			weekArr[i - 1] = dayStr;
		}
		return weekArr;
	}
	
	/*
	 * 获取上一周数组
	 */
	owner.getPreviousWholeWeek = function(dateStr){
		var previousDay = reduceSomeDayToDate(dateStr,7);
		return owner.getWholeWeek(previousDay);
	}
	
	/*
	 * 获取下一周数组
	 */
	owner.getNextWholeWeek = function(dateStr){
		var nextDay = addSomeDayToDate(dateStr,7);
		return owner.getWholeWeek(nextDay);
	}
	owner.getWeekIndex = function(dateStr){
		var yearMonth = dateStr.substring(0,7);
		var tempDay = dateStr;
		var index = 0;
		for (var i = 0; i < 6;i++) {
			var arr = owner.getWholeWeek(tempDay);
			var first = arr[0];
			var firstYm = first.substring(0,7);
			if (firstYm == yearMonth) {
				index++;
				tempDay = first;
				tempDay = owner.getPreviousDate(tempDay);
			}else{
				var last = arr[6];
				var lastYm = last.substring(0,7);
				if (lastYm == yearMonth) {
					index++;
				}
				break;
			}
		}
		return index;
	}
	
	owner.getHanziWeekday = function (dateStr){
		var date = changeStrToDate(dateStr);
		var zhouji = date.getDay();
		var zhouArr = ['日','一','二','三','四','五','六'];
		return zhouArr[zhouji];
	}
	owner.getNumberWeekday = function (dateStr){
		var date = changeStrToDate(dateStr);
		var zhouji = date.getDay();
		var zhouArr = [7,1,2,3,4,5,6];
		return zhouArr[zhouji]
	}
	owner.getNextYearMonthStr = function(dateStr){
		var ymdArr = getYearMonthDay(dateStr);
		var mInt = ymdArr[1];
		if (mInt < 12) {
			mInt += 1;
			if (mInt < 10) {
				return ymdArr[0] + '-0' + mInt;
			}
			return ymdArr[0] + '-' + mInt;
		}else{
			var yInt = ymdArr[0];
			yInt += 1;
			mInt = 1;
			return yInt + '-0' + mInt;
		}
	}
	owner.getPreviousYearMonthStr = function(dateStr){
		var ymdArr = getYearMonthDay(dateStr);
		var mInt = ymdArr[1];
		if (mInt > 1) {
			mInt -= 1;
			if (mInt < 10) {
				return ymdArr[0] + '-0' + mInt;
			}
			return ymdArr[0] + '-' + mInt;
		}else{
			var yInt = ymdArr[0];
			yInt -= 1;
			mInt = 12;
			return yInt + '-' + mInt;
		}
	}
	
	function addSomeDayToDate(dateStr,dayNum){
		var date1 = changeStrToDate(dateStr);
		var daytime = date1.getTime() + 1000 * 60 * 60 * 24*dayNum ;
		var newDate = new Date(daytime);
		var thisDay = changeDateToStr(newDate);
		return thisDay;
	}
	function reduceSomeDayToDate(dateStr,dayNum){
		var date1 = changeStrToDate(dateStr);
		var daytime = date1.getTime() - 1000 * 60 * 60 * 24*dayNum;
		var newDate = new Date(daytime);
		var thisDay = changeDateToStr(newDate);
		return thisDay;
	}
	
	function changeDateToStr(dateObj){
		var cyear = dateObj.getFullYear();
		var cmonth = dateObj.getMonth() + 1;
		var cday = dateObj.getDate();
		var thisDay = cyear + "-";
		if(cmonth < 10) {
			thisDay += "0";
		}
		thisDay += cmonth + "-";
		if(cday < 10) {
			thisDay += "0";
		}
		thisDay += cday;
		return thisDay;
	}
	function changeStrToDate(dateStr){
		var dateArr = getYearMonthDay(dateStr);
		var year = dateArr[0];
		var month = dateArr[1] - 1;
		var day = dateArr[2];
		var date = new Date(year, month, day, 5, 0, 0);
		return date;
	}
	
	function getYearMonthDay(dateStr){
		var ymdStr = dateStr.split(' ')[0];
		var ymdArr = ymdStr.split('-');
		var year = ymdArr[0];
		if (year.length == 2) {
			year = '20' + year;
		}
		var month = ymdArr[1];
		if (month.indexOf('0') == 0) {
			month = month.substring(1);
		}
		var day = null;
		if (ymdArr.length == 3) {
			day = ymdArr[2];
			if (day.indexOf('0') == 0) {
				day = day.substring(1);
			}
			return [parseInt(year),parseInt(month),parseInt(day)];
		}else{
			return [parseInt(year),parseInt(month),1];
		}
	}
	
	function dealYmdw(ymdw,currDate){
		var ymdwArr = ymdw.split('-');
		var ymdwStr = '';
		for (var i = 0; i < ymdwArr.length;i++) {
			var oneStr = ymdwArr[i].toUpperCase();
			if (oneStr.indexOf('YY') >= 0) {
				var year = currDate.getFullYear() + '';
				year = year.substring(year.length - oneStr.length);
				if (i == 0) {
					ymdwStr = year;
				}else{
					ymdwStr += '-' + year;
				}
			}else if (oneStr == 'MM') {
				var month = currDate.getMonth();
				month += 1;
				if (month < 10) {
					month = '0' + month;
				}
				if (i == 0) {
					ymdwStr = month;
				}else{
					ymdwStr += '-' + month;
				}
			}else if (oneStr == 'DD') {
				var day = currDate.getDate();
				if (day < 10) {
					day = '0' + day;
				}
				if (i == 0) {
					ymdwStr = day;
				}else{
					ymdwStr += '-' + day;
				}
			}
		}
		return ymdwStr;
	}
	function dealHsm(hsm,currDate){
		var hsmArr = hms.split(':');
		var hsmStr = '';
		for (var i = 0; i < hsmArr.length;i++) {
			var oneStr = hsmArr[i].toUpperCase();
			if (oneStr == 'HH') {
				var hour = currDate.getHours();
				if (hour < 10) {
					hour = '0' + hour;
				}
				hsmStr += hour;
			}else if (oneStr == 'MM') {
				var minute = currDate.getMinutes();
				if (minute < 10) {
					minute = '0' + minute;
				}
				hsmStr += ":" + minute;
			}else if (oneStr == 'SS') {
				var second = currDate.getSeconds();
				if (second < 10) {
					second = '0' + second;
				}
				hsmStr += ":" + second;
			}
		}
		return hsmStr;
	}
})(mui,window.DHCDate = {});
